package TrackModel;

/**
 * @author Jordan
 *Sub-Class of Block that adds additional functionality for a Station Block
 */
public class StationBlock extends Block
{
	private String stationName;
	private int[] connectingStations;
	
	/**Constructor for a Station Block object.
	 * @param theBlock - The String array containing the attributes that make up this object
	 */
	public StationBlock(String[] theBlock)
	{
		super(theBlock);
		stationName = theBlock[11];
		String[] parts = theBlock[12].split(":");
		connectingStations = new int[parts.length];
		for (int i = 0; i < parts.length; i++)
		{
			connectingStations[i] = Integer.parseInt(parts[i]);
		}
	}
	
	/**
	 * @return Returns the name of the station as a String
	 */
	public String getStationName()
	{
		return stationName;
	}
	
	/**
	 * @return Returns an integer array containing the block IDs of the Station Blocks that can be traveled to directly from this Station Block
	 */
	public int[] getConnectingStations()
	{
		return connectingStations;
	}
	
	/* (non-Javadoc)
	 * @see TrackModel.Block#toString()
	 * Returns a String representation of this Station Block object
	 */
	public String toString()
	{
		StringBuilder other = new StringBuilder();
		if (isUnderground)
			other.append("Underground ");
		other.append(stationName);
		other.append(" Station\n");
		
		if (connections.length == 1)
			return "Block ID: "+blockID+"\tLength: "+length+"\tGrade: "+grade+"\tSpeed Limit: "+speedLimit+"\nElevation: "+elevation+"\t"
					+ "Connected to Block: "+connections[0]+"\nOther information: "+other.toString();
		else
			return "Block ID: "+blockID+"\tLength: "+length+"\tGrade: "+grade+"\tSpeed Limit: "+speedLimit+"\nElevation: "+elevation+"\t"
					+ "Connected to Blocks: "+connections[0]+", "+connections[1]+"\nOther information: "+other.toString();
	}
}